#include "../includes/queue.h"

void init_queue(queue_t *q){
    q->len = 0;
    for (int i = 0; i < MAX_SIZE; ++i){
        q->fd[i] = 0;
    }
}


void insert_queue(queue_t *q, char* str, int fd){
    if (q->len < MAX_SIZE-1){
        strcpy(q->queue[q->len].str, str);
        q->queue[q->len].fd = fd;
        q->len++;
        q->fd[fd] = 1;
    }
    else{
        perror("QUEUE IS FULL");
        exit(6);
    }
}


int is_empty_queue(const queue_t *q){
    if (q->len <= 0)
        return 1;
    else
        return 0;
}


void remove_queue(queue_t *q, int fd){
    for (int i = 0; i < q->len; ++i){
        strcpy(q->queue[i].str, q->queue[i+1].str);
        q->queue[i].fd = q->queue[i+1].fd;
    }

    q->fd[fd] = 0;
    q->len--;
}


int is_in_queue(queue_t *q, int fd){
    if (q->fd[fd] == 1)
        return 1;
        
    return 0;
}